<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>登录</title> 
    <script src="../js/jquery.min.js"></script>
    <link type="text/css" href="../css/login.css" rel="stylesheet" />

</head>
<body>
    <div class="page">
        <div class="container">
            <div class="left">
                <div></div> 
                <div class="login"><img src="../favicon.ico" height="30" alt="" /> DevSupport平台</div>
                <div class="eula">欢迎使用！</div>
                <div class="eula">用户名：admin，密码：admin</div>
            </div>
            <div class="right">             
                <div class="form">
                    <label for="email">用户名</label>
                    <input type="text" id="email" style="border: none; border-bottom: 1px solid #0da2dd ">
                    <label for="password">密码</label>
                    <input type="password" id="password" style="border: none; border-bottom: 1px solid #0da2dd ">
                    <input type="submit" id="submit" onclick="submit()" value="登 录" class="submit-login"> 
                </div>
            </div>
        </div>
    </div>

    <script> 
        function submit() {
            let postdata = {
                "UserName": $("#email").val(),
                "Pwd": $("#password").val(),
            };
            if (!(postdata.UserName && postdata.Pwd)) {
                alert('参数不正确');
                return;
            }
            submit_setAttr();
            $.ajax({
                url: "/api/Login",
                type: "POST",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(postdata),
                dataType: 'json',
                success: function (data) {  
                    setTimeout(() => {
                        submit_delAttr();
                    }, 1000);
                    console.log(data);
                    if (data?.code == 1) {
                        window.location.href = "/";
                    } else { 
                        alert('参数不正确');
                    }
                }
            });
        };
        function submit_setAttr() {
            $("#submit").val("loading......");
            $("#submit").attr("disabled", "disabled");
            $("#submit").addClass('submit-loading');   
        };
        function submit_delAttr() {
            $("#submit").removeAttr('disabled');
            $("#submit").removeClass();
            $("#submit").addClass('submit-login');
            $("#submit").val("登 录");
        };
    </script>

</body>
</html>